<?php
namespace app\index\controller;
use think\Controller;
use think\View;
use think\Session;

class Index extends Controller
{
	public function _initialize()
	{
		if(!Session::has("name")){
			$this->success("请登录","Student/login");
		}
	}

    
    public function say()
    {
    	//模板渲染
       //$smarty->display("say.html");
        //$view = new View();
        //return $view->fetch();
        //助手函数
      //  return  view();
      $name = "张三";
     // $this->assign("name",$name);
     $n = 100;
     $arr=[100,200,300];
      return $this->fetch('say',[
      		'name'=>$name,
      		'n'=>$n,
      		'arr'=>$arr,
      ]);
    }
    
    public function insert()
    {
    	$flag=false;
    	if($flag){
    		$this->success('新增成功', 'Index/index');
    	}else{
    		$this->error("新增失败");
    	}
    	
    }
    
    public function test()
    {
    	//$this->assign("name","hello php");
    	$arr = ['hello','world','hehe'];
    	return $this->fetch("test",[
    		"name" =>"hello PHP",	
    		"num" => 1000,	
    		"arr" => $arr,
    	]);//操作的名称就是模板文件的名称
    }
    
    
    public function index()
    {
    	echo Session::get("name");
    }
    
    
}
